package com.diver.flinkdemo.mapper.mysqlMapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.diver.flinkdemo.entity.Trd.ProvincialZhongTai.ProvincialZTUserInfo;
import com.diver.flinkdemo.entity.xxt.User;
import com.diver.flinkdemo.entity.xxt.UserLogin;
import com.diver.flinkdemo.entity.xxt.UserStudentCard;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by wenjun on 2018/7/5.
 */
@Mapper
//@Component
public interface UserStudentCardMapper extends BaseMapper<UserStudentCard> {

    @Update("update user_student_card set is_tip = #{isTip},is_last_use=#{isLastUse} where user_id = #{userId} and student_card_id = #{studentCardId} ")
    void doUpdateModelByUserIdAndStuId(UserStudentCard userStudentCard);

    @Delete("delete from user_student_card where user_id = #{userId} and student_card_id = #{studentCardId}")
    void doDeleteModel(UserStudentCard userStudentCard);

    @Update("update `user_student_card` set `is_last_use`= IF(`student_card_id`= #{studentCardId},1,0) where user_id=#{userId} ")
    int changeStudentCard(@Param("userId") String userId, @Param("studentCardId") String studentCardId);

    List<UserStudentCard> queryBindCardByCardVersion(@Param("userId") String userId, List<String> cardTypes);


    void batchDelete(@Param("studentCardIdList") List<String> studentCardIdList);

    List<UserStudentCard> getBindsByStudentCardIds(@Param("studentCardIdList") List<String> studentCardIdList);

    @Select("select id, open_id, account_id, name, telphone from user u " +
            "left join `user_student_card` s on u.id = user_id " +
            "where s.`student_card_id` = #{studentCardId} " +
            "and account_id=#{accountId} limit 1")
    List<User> queryBindUserCount(@Param("studentCardId") String studentCardId, @Param("accountId") String accountId);

    @Delete("delete from user_student_card where student_card_id = #{studentCardId}")
    void doPrimaryDeleteModel(UserStudentCard userStudentCard);

    List<UserStudentCard> getBindUserStudentCardByStudentCardId(@Param("studentCardId") String studentCardId);

    List<String> bindBackUp();

    List<String>getBindOpenId(String imei);

    int insertBind(UserLogin loginModel);

    String imeiBindPhone(String imei);

    String getOpenId(String userId);

    @Delete("delete from user_student_card where student_card_id = #{studentCardId}")
    void deleteByStudentCardId(@Param("studentCardId") String studentCardId);

    List<ProvincialZTUserInfo> getProvincialZTUserInfo(@Param("personId") String personId);
}
